package com.yidu.best.stock.stockTrade.controller;
import java.io.InputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.yidu.best.stock.stockTrade.domain.StockTradeVo;
import com.yidu.best.stock.stockTrade.service.StockTradeService;

@Controller
@RequestMapping("stock")
public class StockTradeController {
	@Autowired
	private StockTradeService stockTradeService;

	public StockTradeController() {
		super();
	}

	public StockTradeController(StockTradeService stockTradeService) {
		super();
		this.stockTradeService = stockTradeService;
	}

	public StockTradeService getStockTradeService() {
		return stockTradeService;
	}

	public void setStockTradeService(StockTradeService stockTradeService) {
		this.stockTradeService = stockTradeService;
	}
	
	/**
	 * 加载股票交易数据信息
	 * @return
	 */
	@RequestMapping(value="stockPlate")
	public String stockPlateList() {
		return "sys/stock/stockList";
		
	}
	/**
	 * 查找所有股票交易数据
	 * @param StockClearingVo 股票交易对象
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="stockTrades",method=RequestMethod.GET)
	public Map<String, Object> queryStockPlateDate(StockTradeVo stockTradeVo){
		Map<String, Object> stockPlateMap =stockTradeService.queryStockPlateByCriteriaWithPage(stockTradeVo); 
		return stockPlateMap;
	}
	
	/**
	 * excel导入数据
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="imports",method=RequestMethod.POST)
    @ResponseBody
    public String impotr(HttpServletRequest request) throws Exception {
       MultipartHttpServletRequest multipart = (MultipartHttpServletRequest) request;
       MultipartFile file = multipart.getFile("file");
       InputStream in = file.getInputStream();
        //数据导入
       stockTradeService.ajaxUploadExcel(in, file);
       in.close();
       return "true";
    }
	
	
	
	@ResponseBody
	@RequestMapping(value="closeStock",method=RequestMethod.GET)
	public boolean closeStock(String tradeStatus, String stockTradeId) {
		return stockTradeService.closeStock(tradeStatus, stockTradeId);
		
	}
	
}
